const execSQL = require("../../db/mysql");
async function getMallHomeCarousel() {
    try {
        let sql =
            "SELECT * FROM picture where carouselChart='首页' and `desc`='轮播'";
        let result = await execSQL(sql);
        return {
            code: 1,
            message: "获取成功",
            data: result,
        };
    } catch (error) {
        
        return {
            code: 0,
            message: "获取失败",
        };
    }
}
async function getHotProduct(name) {
    try {
        
        let arr = {
            爆款商品:
                "SELECT product.*,picture.url,picture.id as pID FROM product,picture where product.id=picture.productID and picture.desc='商品展示' Limit 7",
            促销商品:
                "SELECT product.*,picture.url,picture.id as pID FROM product,picture where product.id=picture.productID and picture.desc='商品展示' and product.sale<1 limit 7",
        };
        
        let sql = arr[name];
        let result = await execSQL(sql);
        return {
            code: 1,
            message: "获取成功",
            data: result,
        };
    } catch (error) {
        return {
            code: 0,
            message: "获取失败",
        };
    }
}
module.exports = {
    getMallHomeCarousel,
    getHotProduct,
};
